const db = wx.cloud.database();
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        phone: 0,
        theList: '',
        thisshow: 0,
        region: ['请选择省份', '请选择地市', '请选择县区'],
        customItem: '全部',
        zkz: '',
        page: 38
    },
    zkzInput: function (e) {
        this.setData({
            zkz: e.detail.value
        })
        console.log(this.data.zkz)
    },
    bindRegionChange: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            region: e.detail.value
        })
        console.log(typeof (e.detail.value))
        let json_arr = e.detail.value
        // let str1 = JSON.stringify(str)
        let str1 = json_arr.join(',')
        console.log(str1)
        this.setData({
            dishi: str1
        })
    },



    onLoad: function (options) {
        var that = this;
        console.log(options)
        that.setData({
            area: options.area,
            geneal: options.agent
        })
        if (options.page) {
            that.setData({
                page: options.page
            })
        }
    },
    getPhoneNumber(e) {
        var that = this;
        wx.cloud.callFunction({
            name: 'getMobile',
            data: {
                weRunData: wx.cloud.CloudID(e.detail.cloudID),
            }
        }).then(res => {
            that.setData({
                mobile: res.result,
            })
            wx.setStorageSync('phone', res.result)
            console.log(res.result)
            wx.request({ //发送请求
                url: "https://zg99.offcn.com/index/biaodan/register/?actid=33533&callback=?",
                data: {
                    dishi: that.data.dishi,
                    zkz: that.data.zkz,
                    phone: res.result,
                    fenxiao: that.data.area,
                    geneal: that.data.geneal
                }, //接收参数
                success(res) { //返回
                    var jsonStr = res.data;
                    jsonStr = jsonStr.replace("(", "");
                    jsonStr = jsonStr.replace(")", "");
                    if (typeof jsonStr != 'object') {
                        jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                        var theJson = JSON.parse(jsonStr);
                    };
                    console.log(theJson)

                    wx.showToast({
                        title: '预约成功！',
                        duration: 3000
                    })
                }
            })

            wx.request({
                url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/wx_collect_info',
                method: 'POST',
                data: {
                    activity_id: 25,
                    mobile: res.result,
                    area_code: that.data.area,
                    agent: that.data.geneal,
                    extra: {
                        dishi: that.data.dishi,
                        zkz: that.data.zkz,
                    },
                    page_index: that.data.page
                },
                success: res => {
                    console.log(res);
                }
            })

        }).catch(err => {
            console.error(err);
        });
    },
    info(e) {
        wx.request({ //发送请求
            url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=35888&callback=?",
            data: {
                province: '山东省',
                city:'',
                limits:'500'
              
            }, //接收参数
            success(res) { //返回
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                };
                console.log(theJson)

            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})